//
//  PictureExampleViewController.m
//  JiFengDaRen
//
//  Created by zhuchao on 16/9/18.
//  Copyright © 2016年 SH_iOS. All rights reserved.
//
/**
 *
 *
 */
#import "PictureExampleViewController.h"
#import "DJCameraViewController.h"
#import "YYText.h"
@interface PictureExampleViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>
@property(nonatomic,strong)UIScrollView *picExampleSv;

@end

@implementation PictureExampleViewController
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
    
    
}

-(void)configUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
    _picExampleSv = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    _picExampleSv.contentSize = CGSizeMake(0, 800);
    _picExampleSv.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_picExampleSv];
    
    
    UILabel *desLabel = [[UILabel alloc]init];
    
    //    [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#508CEE"] range:NSMakeRange(0, 5)];
    //    [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#508CEE"] range:NSMakeRange(attributedStr.length - 58, 6)];
    //    desLabel.numberOfLines = 0;
    desLabel.textColor = KSHGRAYTEXTCOLOR;
    desLabel.numberOfLines = 0;
    desLabel.font = KSystemFont(__I6Width(13));
    [_picExampleSv addSubview:desLabel];
    
    NSString *desLabelText;
    
    switch (self.index) {
        case 1000:
            
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将身份证正面拍照,请确保身份证清晰可见无反光,无任何修饰痕迹。\n2.下面照片仅供参考";            break;
        case 1001:
            
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将身份证反面拍照,请确保身份证清晰可见无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            break;
        case 1002:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请手持身份证正面,表情自然,请确保身份证姓名,号码以及储蓄卡卡号,持卡人姓名清晰可见。\n2.不要遮挡面部,建议免冠,露出双耳为佳。\n3.不要过度曝光或过暗。\n4.以脸部占相框1/2以上为佳。\n5.照片内不要出现其他人员。\n6.下面照片仅供参考";
            break;
        case 1003:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将本人名下的借记卡正面拍照,请确保借记卡清晰可见无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            break;
        case 1004:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将本人名下的借记卡背面拍照,请确保借记卡清晰可见无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            break;

        case 2000:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将商店营业执照进行拍照,确保画面清晰,做到可以看清照片字体,不模糊,无任何修饰痕迹。\n2.下面照片仅供参考";
            
            break;
        case 2001:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将门店正面拍照,确保店面画面清晰,无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            
            break;
        case 2002:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将商店内收银台拍照,确保画面清晰,不模糊,无任何修饰痕迹。\n2.下面照片仅供参考";
            
            break;
        case 2003:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将商店布局进行拍照,确保画面清晰,无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            
            break;
        case 2004:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将商店布局进行拍照,确保画面清晰,无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            
            break;
        case 2005:
            desLabelText = @"为了提高您的通过率，先阅读拍照规范\n\n1.请将商店布局进行拍照,确保画面清晰,无反光,无任何修饰痕迹。\n2.下面照片仅供参考";
            
            break;
        default:
            break;
    }
    
    NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:desLabelText];
    attributedStr.yy_lineSpacing = 3;
    desLabel.attributedText = attributedStr;
    CGFloat deslabeHeight =   [Tool getTextHeightWithText:desLabel.text width:(KScreenWidth - __I6Width(20)* 2) font:KSystemFont(13)] + __I6Height(26);
    desLabel.frame = CGRectMake(__I6Width(20), __I6Height(15), KScreenWidth - __I6Width(20) * 2, deslabeHeight);
    
    
    UIImageView *picture = [[UIImageView alloc]init];
    if (self.index == 1002) {
        picture.frame =  CGRectMake((KScreenWidth -__I6Width(489*0.5))/2 ,deslabeHeight + __I6Height(40), __I6Width(486*0.5), __I6Height(599*0.5));
    }else if(self.index == 2000 || self.index == 2001 ||self.index == 2002 || self.index == 2003 || self.index == 2004 || self.index == 2005){
        // 648 392
        picture.frame =  CGRectMake((KScreenWidth -__I6Width(648*0.5))/2 ,deslabeHeight + __I6Height(40), __I6Width(648*0.5), __I6Height(392*0.5));
        
        
    }else{
        picture.frame =  CGRectMake((KScreenWidth -__I6Width(489*0.5))/2 ,deslabeHeight + __I6Height(40), __I6Width(489*0.5), __I6Height(309*0.5));
    }
    
    
    [_picExampleSv addSubview:picture];
    
    
    
    UIButton *takePhoto = [[UIButton alloc]init];
    if (self.index == 1002) {
        takePhoto.frame =  CGRectMake((KScreenWidth -__I6Width(326))/2 , deslabeHeight + __I6Height(40) + __I6Height(599 * 0.5) + __I6Height(80), __I6Width(326), __I6Height(42));
        
        
    }else if(self.index == 2000 || self.index == 2001 ||self.index == 2002 || self.index == 2003 || self.index == 2004 || self.index == 2005){
        // 648 392
        
        takePhoto.frame =  CGRectMake((KScreenWidth -__I6Width(326))/2 , deslabeHeight + __I6Height(40) + __I6Height(392 * 0.5) + __I6Height(80), __I6Width(326), __I6Height(42));
        
        
    }else{
        takePhoto.frame =  CGRectMake((KScreenWidth -__I6Width(326))/2 , deslabeHeight + __I6Height(40) + __I6Height(309 * 0.5) + __I6Height(80), __I6Width(326), __I6Height(42));
        
    }
    
    takePhoto.layer.cornerRadius = __I6Height(8);
    takePhoto.layer.masksToBounds = YES;
    takePhoto.titleLabel.font = KSHSystemFont(16);
    [takePhoto setBackgroundImage:[UIImage imageNamed:@"navImage"] forState:UIControlStateNormal];
    [takePhoto setTitle:@"拍照" forState:UIControlStateNormal];
    [takePhoto addTarget:self action:@selector(takePhoto:) forControlEvents:UIControlEventTouchUpInside];
    [_picExampleSv addSubview:takePhoto];
    
    
    
    
    switch (self.index) {
        case 1000:
            self.title = @"身份证正面照";
            picture.image = [UIImage imageNamed:@"identification_fore@2x"];
            break;
        case 1001:
            self.title = @"身份证反面照";
            picture.image = [UIImage imageNamed:@"identification_back@2x"];
            break;
        case 1002:
            self.title = @"手持身份证和银行卡";
            picture.image = [UIImage imageNamed:@"certification_with_hold@2x"];
            break;
        case 1003:
            self.title = @"上传银行卡正面";
            picture.image = [UIImage imageNamed:@"bank_card_fore@2x"];
            break;
        case 1004:
            self.title = @"上传银行卡背面";
            
            picture.image = [UIImage imageNamed:@"bank_card_back@2x"];
            break;
        case 2000:
            self.title = @"上传营业执照";
            picture.image = [UIImage imageNamed:@"sh_merchat_license"];
            
            break;
        case 2001:
            self.title =  @"上传门头照";
            picture.image = [UIImage imageNamed:@"sh_merchat_door"];
            
            break;
        case 2002:
            self.title  = @"上传店内照";
            picture.image = [UIImage imageNamed:@"sh_merchat_inside_one"];
            
            break;
        case 2003:
            self.title  = @"上传店内照";
            picture.image = [UIImage imageNamed:@"sh_merchat_inside_ohter"];
            
            break;
        case 2004:
            self.title  = @"上传店内照";
            picture.image = [UIImage imageNamed:@"sh_merchat_inside_ohter"];
            
            break;
        case 2005:
            self.title  = @"上传店内照";
            picture.image = [UIImage imageNamed:@"sh_merchat_inside_ohter"];
            
            break;
        default:
            break;
    }
    
}
//从相册选择
- (void)LocalPhoto
{
    //打开系统相册
    [self openImagePickerController:UIImagePickerControllerSourceTypePhotoLibrary];
    
}

//拍照
- (void)takePhoto:(UIButton *)sender
{
    
    
    //判断相机是否可用
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        
        
        
        //打开相机
        self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
        DJCameraViewController *CameraVc =  [[DJCameraViewController alloc]init];
        [self.navigationController pushViewController:CameraVc animated:YES];
        
        
        
        
    }else{
        
        
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"相机不可用" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        
        [alert show];
    }
}
-(void)openImagePickerController:(UIImagePickerControllerSourceType)type
{
    if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        type = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    UIImagePickerController  *picker = [[UIImagePickerController alloc]init];
    //指定资源类型
    picker.sourceType = type;
    //允许编辑
    picker.allowsEditing = YES;
    picker.delegate = self;
    //弹出
    [self presentViewController:picker animated:YES completion:nil];
    
    
    
}
#pragma mark - 代理
#pragma mark 点击取消按钮 退出相机
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    
    
    
}



#define KQN @"http://7xqkwk.com1.z0.glb.clouddn.com/"
#pragma mark 点击选择按钮
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
